<template>
    <div class="vea-header">
        <div class="vea-title">
            后台管理系统
        </div>
        <div class="vea-nav">
            <div>
                <el-button :icon="hideMenuBtn" size="small" plain @click="emit('menuHideShow')"/>
            </div>
            <el-dropdown @command="handleCommand" class="vea-menu">
                <div class="vea-menu-title">
                    <el-avatar src="/img/icons/admin5.png" fit="cover"></el-avatar>
                    <span style="padding-left: 10px">{{ userInfo.nick_name }}</span>
                    <el-icon>
                        <CaretBottom/>
                    </el-icon>
                </div>
                <template #dropdown>
                    <el-dropdown-menu>
                        <el-dropdown-item command="modify"><i class="el-icon-edit"></i> 修改密码</el-dropdown-item>
                        <el-dropdown-item command="logout"><i class="el-icon-switch-button"></i> 退出登录
                        </el-dropdown-item>
                    </el-dropdown-menu>
                </template>
            </el-dropdown>
        </div>
    </div>
</template>

<script setup>
import {computed, defineProps, defineEmits, onMounted} from "vue";
import {useStore} from "vuex";

const prop = defineProps({
    open_btn: {
        default: () => false,
        type: Boolean
    }
})
const emit = defineEmits(['menuHideShow'])

const hideMenuBtn = computed(() => {
    return prop.open_btn ? "Expand" : "Fold"
})

const store = useStore();
const userInfo = computed(() => {
    return store.state.accounts || {}
})
onMounted(() => {
    store.commit("getAccount")
})
</script>

<style lang="less" scoped>
.vea-header {
  height: 45px;
  background: var(--default-color);
  display: flex;
  align-items: center;
  //justify-content: space-between;
  box-sizing: border-box;

  .vea-title {
    font-size: 20px;
    box-sizing: border-box;
    padding: 10px;
    background: rgba(255, 255, 2255, .6);
    height: 100%;
    color: #ffffff;
    width: 220px;
    letter-spacing: .8rem;
  }

  .vea-nav {
    display: flex;
    justify-content: space-between;
    width: calc(100% - 225px);
    margin-left: 5px;
    align-items: center;

    .vea-menu {
      padding: 10px;
      color: #fff;

      .vea-menu-title {
        display: flex;
        align-items: center;
      }
    }
  }


}
</style>